#!/usr/bin/perl
#index.cgi

require './remotesync-lib.pl';
$mark=&is_exit_usrvol();
#$mark=0;
&ReadParse();

if($mark==0){

   &header($text{'mirror_title'}, "", "index", 0, 1,);
#  print "There is no user volume on this NAS! You can not do any mirror job!";
   print $text{'mirror_no_usrvol'}; 
   &footer("/", $text{'index'});

}

if($mark==1){

   &header($text{'mirror_title'}, "", "index", 0, 1,);
   print "<form name=editform action=index.cgi method=post onsubmit='return onsubmit_form();'>\n";
   &list_jobs();

   print "<input type=hidden name=command>\n";
   print "<input type=hidden name=sharepath>\n";

   print "</form>\n";
   &footer("/", $text{'index'});

}

#javascript
print <<EOF;
<script>
function onsubmit_form()
{
    document.editform.exec.disabled = true;
    document.editform.config.disabled = true;
    document.editform.jobdel.disabled = true;
    document.editform.newmirror.disabled = true;

}

function on_exec_click(length)
{
    var i;
    var find = 0;
    if(length < 2)
    {
          if(length < 1)
          {
              return false;
          }
          else
          {
              if(document.editform.sharedir.checked)
              {
                   find = 1;
              }
          }
    }
    else
    {
          for(i = 0; i < length; i++)
          {   
              if(document.editform.sharedir[i].checked)
              {
                   find = 1;
              }
   
          }
    }
    if(find == 0)
    {
          alert("$text{'noselect'}");
          return false;
    }
   
    document.editform.command.value = 'exec';
    document.editform.action = 'exec.cgi';
    
}

function on_config_click(length)
{
    var i;
    var find = 0;
    if(length < 2)
    {
        if(length < 1)
        {
            return false;
        }
        else
        {
            if(document.editform.sharedir.checked)
            {
                 find = 1;
            }
        } 
    }
    else
    {
        for(i = 0; i < length; i++)
        {
            if(document.editform.sharedir[i].checked)
            {
                 find = 1; 
            }    
        }
    }
    if(find == 0)
    {
        alert("$text{'noselect'}");
        return false;
    }
    document.editform.action = 'edit_rsync.cgi';
    document.editform.command.value = 'config';
}

function on_jobdel_click(length)
{
    var i;
    var find = 0;
    if(length < 2)
    {
        if(length < 1)
        {
            return false;
        }
        else
        { 
            if(document.editform.sharedir.checked)
            {
                find = 1;
            }
        }
    }
    else
    {
        for(i = 0; i < length; i++)
        {
            if(document.editform.sharedir[i].checked)
            { 
                find = 1;
            }
        }

    }
    
    if(find == 0)
    {
        alert("$text{'noselect'}");
        return false;
    }
    if(!confirm("$text{'delconfirm'}"))
    {
       return false;
    }
    document.editform.command.value = 'jobdel'; 
    document.editform.action = 'deljob.cgi';
}

function on_newmirror_click()
{   

    document.editform.action = 'creat_rsync.cgi';
    document.editform.command.value = 'newmirror'; 
}

function on_newjob_click()
{

    document.editform.command.value = 'newjob';
    document.editform.action = 'creat_rsync.cgi';

}

</script>
EOF

#print "<input type=hidden name=command>\n";
#print "<input type=hidden name=sharepath>\n";
#print "<input type=hidden name=src value='disk'>\n";


#print "</form>\n";
#&footer("/", $text{'index'});
